/*
 * fsdata_custom.c
 *
 * Created: 2/9/2018 9:23:18 AM
 *  Author: rico
 */
#include "lwip/opt.h"
#include "lwip/def.h"
#include "fs.h"
#include "fsdata.h"
// #include "ff.h"
#include <string.h>
#include "flashFs.h"
#if LWIP_HTTPD_CUSTOM_FILES
/*-----------------------------------------------------------------------------------*/
extern "C"
{
	int fs_open_custom(struct fs_file *file, const char *name)
	{
		FlashFile *fp = new FlashFile();
		if (fp->open_rdonly(name) == 0)
		{
			file->len = fp->size();
		}
		else
		{
			file->len = 0;
		}
		file->file_object = fp;
		file->data = "";
		file->index = 0;
		file->pextension = NULL;
		return file->len;
	}

	/*-----------------------------------------------------------------------------------*/
	void fs_close_custom(struct fs_file *file)
	{
		FlashFile *fp = (FlashFile *)file->file_object;
		fp->close();
		delete fp;
	}
	int fs_read_custom(struct fs_file *file, char *buffer, int count)
	{
		FlashFile *fp = (FlashFile *)file->file_object;
		return fp->read(buffer, count);
	}
}
#endif